# See LICENSE for licensing information.
PROJECT = elcache
VERSION=0.0.3

CHMOD = $(shell chmod a+x ./rebar3)

REBAR = ./rebar3

.PHONY: deps build version release console doc clean distclean

all: clean build

deps:
	@$(CHMOD)
	@$(REBAR) get-deps

build:
	@$(CHMOD)
	@$(REBAR) compile

version:
	@echo "Setting ${PROJECT} version:$(VERSION)"
	@perl -p -i -e "s/^\s*{vsn,.*/  {vsn, \"$(VERSION)\"},/g" src/${PROJECT}.app.src
	@perl -p -i -e "s/^{relx,.*/{relx, [{release, {${PROJECT} , \"$(VERSION)\"},/g" rebar.config
	@perl -p -i -e "s/^{.*/{\"$(VERSION)\",/g" src/${PROJECT}.appup.src
	@echo "Done"

upgrade:
	@$(CHMOD)
	@$(REBAR) upgrade

release:
	@$(CHMOD)
	@$(REBAR) release

console:
	./_build/default/rel/${PROJECT}/bin/${PROJECT} console

doc:
	@$(CHMOD)
	@$(REBAR) edoc

clean:
	@$(CHMOD)
	@$(REBAR) clean

distclean: clean
	@$(REBAR) delete-deps

.PHONY: pack relup test

pack:
	@$(CHMOD)
	@$(REBAR) as ${VERSION} tar

test:
	@$(CHMOD)
	@$(REBAR) ct
	@$(REBAR) eunit

